package com.example.littleSpider.myapplication.activity;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;

import com.example.littleSpider.myapplication.R;
import com.example.littleSpider.myapplication.base.BaseActivity;
import com.example.littleSpider.myapplication.fragment.gankuai.mydelivery.MydeliveryAllFragment;
import com.example.littleSpider.myapplication.fragment.gankuai.mydelivery.MydeliveryPendingPickupFragment;
import com.example.littleSpider.myapplication.fragment.gankuai.mydelivery.MydeliverycompletedFragment;
import com.example.littleSpider.myapplication.fragment.gankuai.mydelivery.MydeliverydispatchFragment;
import com.example.littleSpider.myapplication.myInterfaces.MethodInTitle;
import com.example.littleSpider.myapplication.view.TitleView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by EDZ on 2017/12/14.
 * <p>
 * 赶快 我的派送界面
 */

public class MyDeliveryActivity extends BaseActivity implements MethodInTitle {


    @BindView(R.id.title_view)
    TitleView title_view;
    @BindView(R.id.mydelivery_tabs)
    TabLayout mydelivery_tabs;
    @BindView(R.id.mydelivery_vp)
    ViewPager mydelivery_vp;

    FragmentManager manager;
    List<Fragment> fragmentList = new ArrayList<>();
    //我的派送各条目
    MydeliveryAllFragment mydeliveryAllFragment = new MydeliveryAllFragment();
    MydeliveryPendingPickupFragment mydeliveryPendingPickupFragment = new MydeliveryPendingPickupFragment();
    MydeliverydispatchFragment mydeliverydispatchFragment = new MydeliverydispatchFragment();
    MydeliverycompletedFragment mydeliverycompletedFragment = new MydeliverycompletedFragment();


    @Override
    protected int getLayoutRes() {
        return R.layout.activity_mydelivery;
    }

    @Override
    protected void initView() {
        title_view.initMyTitle("赶快-我的派送", this, false);
        title_view.hideTitleTextImage();

        fragmentList.add(mydeliveryAllFragment);
        fragmentList.add(mydeliveryPendingPickupFragment);
        fragmentList.add(mydeliverydispatchFragment);
        fragmentList.add(mydeliverycompletedFragment);

        manager = getSupportFragmentManager();
        mydelivery_tabs.setupWithViewPager(mydelivery_vp);
        mydelivery_vp.setAdapter(new MyPageAdapter(manager));
    }



    class MyPageAdapter extends FragmentPagerAdapter {

        FragmentManager manager;

        public MyPageAdapter(FragmentManager fm) {
            super(fm);
            manager = fm;
        }

        @Override
        public Fragment getItem(int position) {
            return fragmentList.get(position);
        }

        @Override
        public int getCount() {
            return fragmentList.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            if (position == 0){
                return "全部";
            }
            if (position == 1){
                return "待取货";
            }
            if (position == 2){
                return "派送中";
            }
            if (position == 3){
                return "已完成";
            }

            return null;
        }

    }

    @Override
    protected void initData() {

    }

    @Override
    public void setGoBack() {
        finish();
    }

    @Override
    public void onRightOne() {

    }

    @Override
    public void onRightTwo() {

    }

    @Override
    public void onTitleText() {

    }
}
